<?php

namespace Database\Seeders;

use App\Models\UserPart;
use App\Models\UserPosture;
use App\Models\UserSymptom;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class BodyInfoSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // 体态
        $posture = [
            ['id' => 1, 'title' => '侧面观', 'image' => '', 'order' => 1],
            ['id' => 2, 'title' => '背面观', 'image' => '', 'order' => 2],
        ];

        // 部位
        $part = [
            // 侧面观
            ['id' => 1, 'title' => '头部', 'posture_id' => 1, 'order' => 1],
            ['id' => 2, 'title' => '颈椎', 'posture_id' => 1, 'order' => 2],
            ['id' => 3, 'title' => '扁胛骨', 'posture_id' => 1, 'order' => 3],
            ['id' => 4, 'title' => '胸椎', 'posture_id' => 1, 'order' => 4],
            ['id' => 5, 'title' => '腰椎', 'posture_id' => 1, 'order' => 5],
            ['id' => 6, 'title' => '骨盆', 'posture_id' => 1, 'order' => 6],
            ['id' => 7, 'title' => '脓关节', 'posture_id' => 1, 'order' => 7],
            // 背面观
            ['id' => 8, 'title' => '颈部', 'posture_id' => 2, 'order' => 1],
            ['id' => 9, 'title' => '肩部', 'posture_id' => 2, 'order' => 2],
            ['id' => 10, 'title' => '扁脾骨', 'posture_id' => 2, 'order' => 3],
            ['id' => 11, 'title' => '胸腰椎', 'posture_id' => 2, 'order' => 4],
            ['id' => 12, 'title' => '骨盆', 'posture_id' => 2, 'order' => 5],
            ['id' => 13, 'title' => '膝关节', 'posture_id' => 2, 'order' => 6],
            ['id' => 14, 'title' => '足弓', 'posture_id' => 2, 'order' => 7],
        ];

        // 症状
        $symptom = [
            // 侧
            // 头部
            ['id' => 1, 'title' => '中立位', 'keyword' => 'side_head_zlw', 'posture_id' => 1, 'part_id' => 1, 'order' => 1],
            ['id' => 2, 'title' => '前引', 'keyword' => 'side_head_qy', 'posture_id' => 1, 'part_id' => 1, 'order' => 2],
            ['id' => 3, 'title' => '后仰', 'keyword' => 'side_head_hy', 'posture_id' => 1, 'part_id' => 1, 'order' => 3],
            // 颈椎 cvb
            ['id' => 4, 'title' => '中心轴', 'keyword' => 'side_cvb_zxz', 'posture_id' => 1, 'part_id' => 2, 'order' => 4],
            ['id' => 5, 'title' => '过于前曲', 'keyword' => 'side_cvb_qq', 'posture_id' => 1, 'part_id' => 2, 'order' => 5],
            ['id' => 6, 'title' => '强直', 'keyword' => 'side_cvb_qz', 'posture_id' => 1, 'part_id' => 2, 'order' => 6],
            // 扁甲骨 pat
            ['id' => 7, 'title' => '中立位', 'keyword' => 'side_pat_zlw', 'posture_id' => 1, 'part_id' => 3, 'order' => 7],
            ['id' => 8, 'title' => '内旋', 'keyword' => 'side_pat_nx', 'posture_id' => 1, 'part_id' => 3, 'order' => 8],
            // 胸椎 thv
            ['id' => 9, 'title' => '中心轴', 'keyword' => 'side_thv_zxz', 'posture_id' => 1, 'part_id' => 4, 'order' => 9],
            ['id' => 10, 'title' => '过于后凸', 'keyword' => 'side_thv_ht', 'posture_id' => 1, 'part_id' => 4, 'order' => 10],
            ['id' => 11, 'title' => '强直', 'keyword' => 'side_thv_qz', 'posture_id' => 1, 'part_id' => 4, 'order' => 11],
            ['id' => 12, 'title' => '富贵包', 'keyword' => 'side_thv_fgb', 'posture_id' => 1, 'part_id' => 4, 'order' => 12],
            // 腰椎 luv
            ['id' => 13, 'title' => '中心轴', 'keyword' => 'side_luv_zxz', 'posture_id' => 1, 'part_id' => 5, 'order' => 13],
            ['id' => 14, 'title' => '过于前曲', 'keyword' => 'side_luv_qq', 'posture_id' => 1, 'part_id' => 5, 'order' => 14],
            ['id' => 15, 'title' => '强直', 'keyword' => 'side_luv_qz', 'posture_id' => 1, 'part_id' => 5, 'order' => 15],
            // 骨盆 ntp
            ['id' => 16, 'title' => '中立位', 'keyword' => 'side_ntp_zlw', 'posture_id' => 1, 'part_id' => 6, 'order' => 16],
            ['id' => 17, 'title' => '前倾', 'keyword' => 'side_ntp_qq', 'posture_id' => 1, 'part_id' => 6, 'order' => 17],
            ['id' => 18, 'title' => '后倾', 'keyword' => 'side_ntp_hq', 'posture_id' => 1, 'part_id' => 6, 'order' => 20],
            // 脓关节 sar
            ['id' => 19, 'title' => '中立位',  'keyword' => 'side_sar_zlw', 'posture_id' => 1, 'part_id' => 7, 'order' => 18],
            ['id' => 20, 'title' => '超伸',  'keyword' => 'side_sar_cs', 'posture_id' => 1, 'part_id' => 7, 'order' => 19],
            // 背 back
            // 颈部
            ['id' => 21, 'title' => '中立位', 'keyword' => 'back_nec_zlw', 'posture_id' => 2, 'part_id' => 8, 'order' => 1],
            ['id' => 22, 'title' => '前倾', 'keyword' => 'back_nec_qq', 'posture_id' => 2, 'part_id' => 8, 'order' => 2],
            ['id' => 23, 'title' => '旋转', 'keyword' => 'back_nec_xz', 'posture_id' => 2, 'part_id' => 8, 'order' => 3],
            // 肩部
            ['id' => 24, 'title' => '中立位', 'keyword' => 'back_sho_zlw', 'posture_id' => 2, 'part_id' => 9, 'order' => 4],
            ['id' => 25, 'title' => '右高', 'keyword' => 'back_sho_yg', 'posture_id' => 2, 'part_id' => 9, 'order' => 5],
            ['id' => 26, 'title' => '左高', 'keyword' => 'back_sho_zg', 'posture_id' => 2, 'part_id' => 9, 'order' => 6],
            // 扁脾骨
            ['id' => 27, 'title' => '中立位', 'keyword' => 'back_pat_zlw', 'posture_id' => 2, 'part_id' => 10, 'order' => 7],
            ['id' => 28, 'title' => '前引（圆扁）', 'keyword' => 'back_pat_qq', 'posture_id' => 2, 'part_id' => 10, 'order' => 8],
            ['id' => 29, 'title' => '后缩口', 'keyword' => 'back_pat_hsk', 'posture_id' => 2, 'part_id' => 10, 'order' => 9],
            // 胸腰椎
            ['id' => 30, 'title' => '中立位', 'keyword' => 'back_tlv_zlw', 'posture_id' => 2, 'part_id' => 11, 'order' => 10],
            ['id' => 31, 'title' => 'S形', 'keyword' => 'back_tlv_s', 'posture_id' => 2, 'part_id' => 11, 'order' => 11],
            ['id' => 32, 'title' => 'C形', 'keyword' => 'back_tlv_c', 'posture_id' => 2, 'part_id' => 11, 'order' => 12],
            // 骨盆
            ['id' => 33, 'title' => '中立位', 'keyword' => 'back_pel_zlw', 'posture_id' => 2, 'part_id' => 12, 'order' => 13],
            ['id' => 34, 'title' => '右侧倾', 'keyword' => 'back_pel_ycq', 'posture_id' => 2, 'part_id' => 12, 'order' => 14],
            ['id' => 35, 'title' => '左侧倾', 'keyword' => 'back_pel_zcq', 'posture_id' => 2, 'part_id' => 12, 'order' => 15],
            // 膝关节 knj
            ['id' => 36, 'title' => '中立位', 'keyword' => 'back_knj_zlw', 'posture_id' => 2, 'part_id' => 13, 'order' => 16],
            ['id' => 37, 'title' => '膝外翻面', 'keyword' => 'back_knj_xwfm', 'posture_id' => 2, 'part_id' => 13, 'order' => 17],
            ['id' => 38, 'title' => '膝内翻', 'keyword' => 'back_knj_xnf', 'posture_id' => 2, 'part_id' => 13, 'order' => 18],
            // 足部
            ['id' => 39, 'title' => '有足弓', 'keyword' => 'back_fot_yzg', 'posture_id' => 2, 'part_id' => 14, 'order' => 19],
            ['id' => 40, 'title' => '扁平足', 'keyword' => 'back_fot_bpz', 'posture_id' => 2, 'part_id' => 14, 'order' => 20],
            ['id' => 41, 'title' => '高足弓', 'keyword' => 'back_fot_gzg', 'posture_id' => 2, 'part_id' => 14, 'order' => 20],
        ];

        DB::table('user_posture')->truncate();
        DB::table('user_part')->truncate();
        DB::table('user_symptom')->truncate();

        DB::beginTransaction();
        try {
            foreach ($posture as $v) {
                $pos = new UserPosture();
                $pos->id = $v['id'];
                $pos->title = $v['title'];
                $pos->order = $v['order'];
                $pos->save();
            }

            foreach ($part as $v) {
                $pat = new UserPart();
                $pat->id = $v['id'];
                $pat->title = $v['title'];
                $pat->posture_id = $v['posture_id'];
                $pat->order = $v['order'];
                $pat->save();
            }

            foreach ($symptom as $v) {
                $sym = new UserSymptom();
                $sym->id = $v['id'];
                $sym->title = $v['title'];
                $sym->posture_id = $v['posture_id'];
                $sym->part_id = $v['part_id'];
                $sym->order = $v['order'];
                $sym->keyword = $v['keyword'];
                $sym->save();
            }

            DB::commit();
        } catch (\Exception $e) {
            DB::rollBack();
            dd($e->getMessage());
        }

    }
}
